<!--
 * @Description: 
 * @Version: 1.0
 * @Autor: gaoluo
 * @Date: 2021-08-20 11:45:53
 * @LastEditors: gaoluo
 * @LastEditTime: 2021-12-04 11:50:58
 * @FilePath: /nhw/src/views/Work/index.vue
-->
<template>
  <Layout
    class="work-container"
    :placeholder="false"
    :leftArrow="false"
    navBackColor="transparent"
    @click-right="toScan"
  >
    <!-- <template #left>
      <Icon name="wap-nav" class="scanBtn" />
    </template> -->
    <template #right>
      <Icon name="scan" class="scanBtn" />
    </template>
    <template #default>
      <!-- 轮播图 start -->
      <Swipe
        class="my-swipe"
        :autoplay="5000"
        indicator-color="#fff"
        @change="swipeChange"
      >
        <SwipeItem
          v-for="value in images"
          :key="value"
          :style="{ height: gridTop + 100 + 'px' }"
        >
          <img :src="value" />
        </SwipeItem>
        <template #indicator>
          <div class="indicators-wrap" :style="{ top: gridTop + 'px' }">
            <i
              class="indicator-item"
              v-for="value in images.length"
              :key="value"
              style="width: 6px; height: 6px"
              :class="{ active: indicatorIndex + 1 === value }"
            ></i>
          </div>
        </template>
      </Swipe>
      <!-- 轮播图 end -->
      <!-- 功能列表 start -->
      <Grid :column-num="4" :border="false" ref="container">
        <GridItem v-for="item in menuList" :key="item.imgUrl" :to="item.path">
          <Icon
            class-prefix="iconfont"
            :name="item.imgUrl"
            size=".67rem"
            color="#E57B31"
          />
          <span class="title">{{ item.text }}</span>
        </GridItem>
      </Grid>
      <!-- 功能列表 end -->
    </template>
  </Layout>
</template>

<script>
import Layout from "components/Layout";
import {
  Icon,
  Swipe,
  SwipeItem,
  Grid,
  GridItem,
  Image as VanImage,
} from "vant";

import slider0 from "assets/img/bannerimg.png";
import slider1 from "assets/img/bannerimg1.png";

import { getMenuList } from "@/api/work.js";

export default {
  name: "Work",

  components: {
    Layout,
    Icon,
    Swipe,
    SwipeItem,
    Grid,
    GridItem,
    VanImage,
  },

  data() {
    return {
      menuList: [
        // {
        //   imgUrl: "yjgl",
        //   path: "/work/emergencyManagement",
        //   menuNo: "89",
        //   rank: "14",
        //   text: "应急管理",
        // },
      ],
      images: [slider0, slider1],
      gridTop: 500,
      indicatorIndex: 0,
    };
  },

  activated() {
    getMenuList().then((res) => {
      if (res.state == 0) {
        this.menuList = res.param.menuList;
        this.$nextTick(() => {
          console.log(this.$refs.container.$el.getBoundingClientRect().top);
          this.gridTop =
            this.$refs.container.$el.getBoundingClientRect().top - 20;
        });
      } else {
        this.$toast.fail("菜单加载失败！");
      }
    });
  },

  mounted() {},

  methods: {
    toScan() {
      window.acceptParameter = (jsonString) => {
        this.toJump(jsonString);
      };
      window.location.href = "luculent:getScanInfo";
    },

    toJump(QRcode) {
      this.$router.push({ name: "EquipmentDetails", query: { code: QRcode } });
    },

    swipeChange(index) {
      this.indicatorIndex = index;
    },
  },
};
</script>

<style lang="less" scoped>
@import url("~assets/font/font.less");
.work-container {
  font-size: inherit;
  background: transparent;
  height: 100%;
  .scanBtn {
    line-height: 64px;
    width: 64px;
    height: 64px;
    border-radius: 14px;
    background: rgba(32, 32, 32, 0.6);
    text-align: center;
  }
  .my-swipe {
    .van-swipe-item {
      color: #fff;
      font-size: 20px;
      text-align: center;
      width: 10rem;
      box-sizing: border-box;
      img {
        width: 100%;
        height: 100%;
        // object-fit: cover;
        object-position: top;
      }
    }
  }

  // 功能按钮
  .van-grid {
    width: 100%;
    background: #fffefd;
    border-radius: 48px 48px 0px 0px;
    overflow: hidden;
    position: fixed;
    left: 0;
    bottom: 1.33333rem;
    padding-top: 18px;
    span.title {
      margin-top: 8px;
      font-size: 26px;
      text-align: center;
      white-space: nowrap;
    }
  }
}

.indicators-wrap {
  position: fixed;
  left: 50%;
  background: rgba(32, 32, 32, 0.6);
  transform: translateX(-50%);
  border-radius: 40px;
  display: flex;
  justify-content: space-between;
  align-content: center;
  padding: 5px 0;
  z-index: 10;
  .indicator-item {
    background: #ebedf0;
    border-radius: 50%;
    margin: 0 8px;
    opacity: 0.3;
    transition: opacity 0.2s, background-color 0.2s;
    &.active {
      background: #fff;
      opacity: 1;
    }
  }
}

/deep/ .van-nav-bar .van-icon {
  color: #fff !important;
}
/deep/.van-swipe__indicators {
  top: 43vh;
}

/deep/.van-grid-item__content {
  padding-top: 10px;
  padding-bottom: 20px;
}
</style>